home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / cp1.zip / IO1.CPP < prev    next >
C/C++ Source or Header  |  1993-06-14  |  3KB  |  112 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville MI
  3. Date: 06-13-93 (12:18)             Number: 136
  4. From: DAVID NUGENT                 Refer#: NONE
  5.   To: ALL                           Recvd: NO  
  6. Subj: [05 of 12] Myio.h              Conf: (37) C++ Langua
  7. ---------------------------------------------------------------------------
  8. // Myio.h
  9. // Specialised I/O class to demonstrate use of C++ iostream
  10. // facilities in a customised environment
  11. // Written by David L Nugent, June 1993.
  12. //
  13.  
  14. # if !defined(_Myio_h)
  15. # define _Myio_h 1
  16.  
  17.     // Foward declare classes
  18.  
  19. class Myio;
  20. class Mystreambuf;
  21. class Mystreambase;
  22. class Mystream;
  23.  
  24.     // Forward declare iostream classes
  25.  
  26. class iostream;
  27.  
  28.     //
  29.     // class Myio
  30.     // This is a simplistic class which simply fields
  31.     // input and output to a simulated stream device.
  32.     //
  33.     // In fact, it doesn't really do much at all other
  34.     // than read input from and send output to a
  35.     // circular queue, as though talking via a loopback
  36.     // pipe to itself.
  37.     //
  38.  
  39.  
  40. class Myio
  41. {
  42.     friend class Mystreambuf;
  43.  
  44.   public:
  45.  
  46.     Myio (int sz =2048);                    // sz = buffer size to allocate
  47.     virtual ~Myio (void);
  48.  
  49.     iostream & stream (void);               // Return (or create) stream
  50.  
  51.     int readok (void) const;                // Underflow check
  52.     int writeok (void) const;               // Overflow check
  53.     int gcount (void) const;                // Get # of chrs last read
  54.     int pcount (void) const;                // Get # of chrs last written
  55.     int count (void) const;                 // Get # of chrs in buffer
  56.     int size (void) const;                  // Get size of buffer
  57.     int dump (void) const;                  // Debugging - dumps buffer
  58.  
  59.     int write (char const * buf, int len);  // Put data into 'pipe'
  60.     int read (char * buf, int max);         // Read data from our 'pipe'
  61.  
  62.   private:
  63.  
  64.     enum
  65.     {
  66.         overflow    = 0x0001,   // Last write only partial
  67.         underflow   = 0x0002    // Last read only partial
  68.     };
  69.  
  70.     unsigned stat;              // Last read/write status
  71.     int _pcount;                // Last write count
  72.     int _gcount;                // Last read count
  73.     int bufsize;                // Size of our buffer
  74.     int bufchars;               // Chrs in buffer now
  75.     int bufidx;                 // Index into buffer (next put)
  76.     char * bufaddr;             // Pointer to buffer
  77.     Mystream * mystream;        // Stream assocated with this object
  78.  
  79. };
  80.  
  81. inline int
  82. Myio::readok (void) const
  83.     {   return ((stat & Myio::underflow) == 0); }
  84.  
  85. inline int
  86. Myio::writeok (void) const
  87.     {   return ((stat & Myio::overflow) == 0);  }
  88.  
  89. inline int
  90. Myio::gcount (void) const
  91.     {   return _gcount;     }
  92.  
  93. inline int
  94. Myio::pcount (void) const
  95.     {   return _pcount;     }
  96.  
  97. inline int
  98. Myio::count (void) const
  99.     {   return bufchars;    }
  100.  
  101. inline int
  102. Myio::size (void) const
  103.     {   return bufsize;     }
  104.  
  105. # endif     // _Myio_h
  106.  
  107. --- MaltEd 1.0.b5
  108.  * Origin: Unique Computing Pty Ltd (3:632/348)
  109. SEEN-BY: 1/211 11/2 4 13/13 101/1 109/25 114/5 123/19 124/1 153/752 154/40
  110. SEEN-BY: 154/77 157/110 159/100 125 140 180 270 430 575 950 203/23 209/209
  111. SEEN-BY: 261/1023 280/1 390/1 396/1 5 15 2430/1 2440/5 3603/20
  112.